package com.ecmap.hongyun.commons.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.ecmap.hongyun.commons.utils.UserUtil;
/**
 * 
 * @className:ManageInterceptor.java
 * @classDescription:前端访问拦截器
 * @author: DANIEL DENG
 * @createTime: 2012-8-20
 *
 */
public class VisitorInterceptor  implements HandlerInterceptor{

	
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e)throws Exception {
		
		
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView ) throws Exception {
		
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		
		if( UserUtil.getUserFromSession(request) != null ){
			return true ;
		}else{
			//重定向到登录界面
			response.sendRedirect(request.getContextPath()+"/to-login"); 
			return false;
		}
		
		
	}

}
